package diamondServer.businesslogic.resource.loader;

import java.io.File;
import java.net.URL;
import java.net.URLClassLoader;

import diamondServer.resources.Message;
import diamondServer.resources.MessageFake;
import diamondServer.resources.Service;
import diamondServer.resources.ServiceFake;



import junit.framework.TestCase;

public class SpecialURLClassLoaderTest
		extends TestCase
{

	private URLClassLoader loader;
	
	protected void setUp() throws Exception
	{
		File f = new File("bin" + File.separator);
		 f.toURI().toURL();
		loader = new SpecialURLClassLoader(new URL[]{
				f.toURI().toURL()
		});
	}

	protected void tearDown() throws Exception
	{
		super.tearDown();
	}

	@SuppressWarnings("unchecked")
	public void testLoadMessageClass() throws ClassNotFoundException
	{
		Class<Message> m =
			(Class<Message>) loader.loadClass(Message.class.getName());
		assertEquals(m.getClassLoader(), 
				Message.class.getClassLoader());
	}
	
	@SuppressWarnings("unchecked")
	public void testLoadServiceClass() throws ClassNotFoundException
	{
		Class<Service> s =
			(Class<Service>) loader.loadClass(Service.class.getName());
		assertEquals(s.getClassLoader(), 
				Service.class.getClassLoader());
	}
	
	@SuppressWarnings("unchecked")
	public void testLoadOtherClass() throws ClassNotFoundException
	{
		Class<MessageFake> mf =
			(Class<MessageFake>) loader.loadClass(MessageFake.class.getName());
		assertEquals(mf.getClassLoader(), loader);
		
		Class<ServiceFake> sf =
			(Class<ServiceFake>) loader.loadClass(ServiceFake.class.getName());
		assertEquals(sf.getClassLoader(), loader);
	}

}
